package hot;

public class Num121 {
    public int maxProfit(int[] prices) {
        int minprice = Integer.MAX_VALUE;
        int max = 0;
        for(int i = 0; i < prices.length; i++) {
            if(prices[i] > minprice) {
                max = Math.max(max,(prices[i] - minprice));
            }else {
                minprice = Math.min(minprice,prices[i]);
            }
        }
        return max;
    }
}
